package com.jh.user.business.impl;

import cn.jh.common.utils.BeanUtil;
import com.jh.user.business.ChannelConfigBusiness;
import com.jh.user.business.DataBusiness;
import com.jh.user.pojo.ChannelConfig;
import com.jh.user.pojo.Data;
import com.jh.user.repository.ChannelConfigRepository;
import com.jh.user.repository.DataRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.util.List;

@Service
public class ChannelConfigBusinessImpl implements ChannelConfigBusiness {

    @Autowired
    private ChannelConfigRepository channelConfigRepository;

    @Autowired
    private EntityManager entityManager;


    @Override
    public ChannelConfig findByTerminalNo(String terminalNo) {
        return channelConfigRepository.findByTerminalNo(terminalNo);
    }

    @Override
    public void save(ChannelConfig channelConfig) {
        channelConfigRepository.save(channelConfig);
        entityManager.flush();
    }

    @Override
    @Transactional
    public void update(ChannelConfig channelConfig) {
        /* 一些属性不予修改 */
        channelConfig.setShopId(null);
        ChannelConfig config = channelConfigRepository.findById(channelConfig.getId());
        BeanUtil.copyPropertiesIgnoreNull(channelConfig, config);
        entityManager.merge(config);
        entityManager.flush();
    }
}
